package club.piclight.LibraryMan;

import club.piclight.LibraryMan.DAO.BookRespository;
import club.piclight.LibraryMan.model.entity.Book;
import club.piclight.LibraryMan.model.entity.ResponseJSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class Controller {

    @Autowired
    private BookRespository bookRespository;

    @RequestMapping("/book")
    public ResponseJSON book(@RequestParam(value = "isbn") String isbn) {
        Book book = bookRespository.getBooksByIsbn(isbn);
        if (book != null)
            return new ResponseJSON(ResponseJSON.STATUS_OK, "ok", book);
        else
            return new ResponseJSON(ResponseJSON.STATUS_NON_INFO, "book not found");
    }
}
